import sys
import os, shutil, stat
import time, datetime
if os.path.isfile('/usr/bin/gnome-session'):
    import file_mimetypeGNOME as mime
else:
    import mime_typeNonGNOME as mime

class AbsynthModLocal:
    def __init__(self):
        return
    def pwd(self):
        return os.getcwd()
    def cwd(self, name):
        os.chdir(name)
    def delete(self, name):
        os.remove(name)
    def rmdir(self, name):
        shutil.rmtree(name)
    def list_file(self, defaultpath = ".", showhidden = 0):
        try:
            mylist, listdata = os.listdir(defaultpath), []
        except: return None
    
        for myitem in mylist:
            if showhidden == 0 and myitem[0] == ".": continue
            mystats = os.stat(os.path.join(".", myitem))
            (txt_type, type, name, size, lastedit) = (os.path.isdir(myitem) and "directory" or "file", 
                                                      os.path.isdir(myitem) and mime.return_folder_mime() or mime.return_mime(myitem), 
            	                                      myitem, 
                                                      str(mystats.st_size), 
                                                      str(datetime.datetime.fromtimestamp(mystats.st_mtime)))
            listdata.append([txt_type, type, name, size, lastedit])
        listdata.sort()
        return listdata